<?php

namespace App\Entities;

class ConvertibleCardSaleRecordEntity extends ABaseEntity
{
    public function __construct(ConvertibleCardSaleRecordModel $model)
    {
        $this->model = $model;
    }

    /**
     * @param string $tradeNo
     * @return ConvertibleCardSaleRecordEntity|null
     */
    public static function findByTradeNo(string $tradeNo)
    {
        $model = ConvertibleCardSaleRecordModel::where('trade_no', $tradeNo)->first();
        if (is_null($model)) {
            return null;
        }
        return new self($model);
    }

    /**
     * @return int
     */
    public function getId()
    {
        return (int)$this->model->id;
    }

    /**
     * 用户ID
     * @return int
     */
    public function getUserId()
    {
        return (int)$this->model->user_id;
    }

    /**
     * 用户ID
     * @param int $userId
     */
    public function setUserId(int $userId)
    {
        $this->model->user_id = $userId;
    }

    /**
     * 交易号
     * @return string
     */
    public function getTradeNo(): string
    {
        return $this->model->trade_no;
    }

    /**
     * 交易号
     * @param string $value
     */
    public function setTradeNo(string $value)
    {
        $this->model->trade_no = $value;
    }

    /**
     * @return int
     */
    public function getConvertibleCardId(): int
    {
        return $this->model->convertible_card_id;
    }

    /**
     * @param int $cardId
     */
    public function setConvertibleCardId(int $cardId)
    {
        $this->model->convertible_card_id = $cardId;
    }

    /**
     * 支付记录状态
     * @return int
     */
    public function getState(): int
    {
        return $this->model->state;
    }

    /**
     * @param int $value
     */
    public function setState(int $value)
    {
        $this->model->state = $value;
    }

    /**
     * 支付时间
     * @return string
     */
    public function getPaidAt(): string
    {
        return $this->model->paid_at ?: '';
    }

    /**
     * @param string $value
     */
    public function setPaidAt(string $value)
    {
        $this->model->paid_at = $value;
    }
}
